﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace 网络权限验证_通用版.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class CommonController : ControllerBase
    {
        private readonly IHttpContextAccessor _contextAccessor;

        public CommonController(IHttpContextAccessor contextAccessor)
        {
            _contextAccessor = contextAccessor;
        }

        [HttpGet]
        public async void Auth(string n1, string n2)
        {
            using (IpinfoContext db = new IpinfoContext())
            {
                db.TIps.Add(new TIp()
                {
                    Ip = _contextAccessor.HttpContext.Connection.RemoteIpAddress.ToString(),
                    Datetime=DateTime.Now,
                    UserName = n1,
                    AppName = n2,
                });
                await db.SaveChangesAsync();
            }
        }
    }
}
